package com.gopay.scheduler.common;

import com.gopay.common.constants.cust.SMSResultConstants;
import com.gopay.common.constants.cust.SMSType;
import com.gopay.remote.user.UserSmsRemoteService;
import com.gopay.remote.vo.UserSendSmsReq;
import org.apache.log4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by liyang on 2017/3/15.
 */
@Component("sendMsg")
public class SendMsg {
    private org.slf4j.Logger logger = LoggerFactory.getLogger(SendMsg.class);

    @Resource(name = "userSmsRemoteClient")
    private UserSmsRemoteService userSmsRemoteClient;

    public void sendSms(String mobileStrs, String sendContent, SMSType smsType) {
        String[] mobileStr = mobileStrs.split(",");
        for( String mob : mobileStr ){
            UserSendSmsReq userSmsReq = new UserSendSmsReq();
            userSmsReq.setMobileNo(mob);
            userSmsReq.setContent(sendContent);
            userSmsReq.setSmsMaxCount(0);
            userSmsReq.setSmsType(smsType);
            logger.error(String.format("===============mob:%s||sendContent:%s==============", mob, sendContent));
            int result = userSmsRemoteClient.sendMobileSMS(userSmsReq);
            if( SMSResultConstants.SEND_RESULT_FAIL == result ){
                logger.error("send sms error!"+result);
            }else if( SMSResultConstants.SEND_RESULT_EXCEED == result ){
                logger.error("send sms error!"+result);
            }else{
                logger.info("send sms success!"+result);
            }
        }
    }
}
